package com.hdax.dm.controller;

import com.hdax.dm.dto.loginDto;
import com.hdax.dm.exceptions.DmException;
import com.hdax.dm.service.loginService;
import com.hdax.dm.utils.response.CommonResponse;
import com.hdax.dm.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class SMSLoginController {

    @Autowired
    private loginService loginService;

    /**
     * 验证码登录
     */
    @PostMapping("msg/login")
    public CommonResponse<loginDto> msglogin(@RequestBody Map<String,String> params){
        return loginService.msglogin(params);
    }

    /**
     * 手机号密码登录
     */
    @PostMapping("login")
    public CommonResponse<loginDto> userlogin(@RequestBody Map<String,String> params){
        return loginService.userlogin(params);
    }

    /**
     * 获取验证码
     */
    @PostMapping("msg")
    public CommonResponse<String>  msg(@RequestBody Map<String,String> params){
        return loginService.msg(params);
    }

    /**
     * 局部异常处理
     */
    @ExceptionHandler(value = {DmException.class})
    public CommonResponse<String> exceptionHandler(DmException e){
        return ResponseUtil.returnFail(e);
    }
}
